package com.probiz.estoresf.product.web.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;

import com.probiz.estore.common.model.product.Product;
import com.probiz.estore.core.controller.GenericStoreFrontController;
import com.probiz.estore.product.service.ProdMainManager;
import com.probiz.estore.product.service.ProductManager;
import com.probiz.estore.webapp.util.RequestUtil;

public class CompareCartFrontController extends		GenericStoreFrontController<Product> {
	private ProductManager	productManager;
	private ProdMainManager	prodMainManager;
	protected void initController() throws Exception {
		mgr = productManager;
	}
	public void setProductManager(ProductManager productManager) {
		this.productManager = productManager;
	}
	
	public void setProdMainManager(ProdMainManager prodMainManager) {
		this.prodMainManager = prodMainManager;
	}	
	public ModelAndView defaultAction(HttpServletRequest request,
			HttpServletResponse response) {
		ModelAndView mv = new ModelAndView("product/compare");
		// ------start:获得对比车上的商品------
		List<Product> compareProductList = prodMainManager.getCompareProductsFromRequest(request);
		mv.addObject("compareProductList",compareProductList);
		// ------end:  获得对比车上的商品------
		if(compareProductList.size() != 0){
			mv.addObject("productAttGroups",compareProductList.get(0).getProductType().getProductAttGroups());
		}
		return mv; 
	}
	/**
	 * 获得商品
	 * @param request
	 * @param response
	 * @return
	 */
	public ModelAndView getProduct(HttpServletRequest request,HttpServletResponse response){
		Product product = productManager.getById(RequestUtil.getInteger(request, "productId"));
		ModelAndView mv = new ModelAndView("product/include/compareCartBarProductItem");
		mv.addObject("product",product);
		return mv;
	}
	
	public ModelAndView refreshBar(HttpServletRequest request,HttpServletResponse response){
		ModelAndView mv = new ModelAndView("product/include/compareCartBarAllItems");
		// ------start:获得对比车上的商品------
		List<Product> compareProductList = prodMainManager.getCompareProductsFromRequest(request);
		mv.addObject("compareProductList",compareProductList);
		// ------end:  获得对比车上的商品------
		return mv;
	}
	
}
